/**
 * 
 * @param id //省份 table Id
 */
provinceId=null;
provinceName=null;
cityId=null;
cityName=null;

function getProvince(id){
	$.ajax({
		type : "get",
		async:false,
		datatype : "json",
		url : "../province/find/all/1/40",
		success : function(data) {
					var rst = JSON.parse(data);
					loadProvinceTable(rst,id);
					
		}	
	});	
}
function loadProvinceTable(json,id){
	for ( var i = 0; i < json.result.data.length; i++) {
		if((i%4)==0){
			$("table[id='"+id+"'] tbody").append("<tr></tr>");
		}
		var pId=getHeadIndexValue(i, json, "id");
		var pName=getHeadIndexValue(i, json, "name");
		var htm="<td>"+pName+"</td><td><input class='common_btn' type='button' value='选择' onclick = \"chooseProvince("+pId+",'"+pName+"')\"></td>	";
		
		$("table[id='"+id+"'] tbody tr:last").append(htm)
		
	}
	var count= 8- $("table[id='"+id+"'] tbody tr:last").children("td").length
	for ( var j = 0; j < count; j++) {
		$("table[id='"+id+"'] tbody tr:last").append("<td></td>");
		
	}

}



function getCity(tableId){
	
	$.ajax({
		type : "get",
		async:false,
		datatype : "json",
		url : "../city/find/provinceId/"+provinceId,
		success : function(data) {
					var rst = JSON.parse(data);
					var obj = DealAndShowMsg(data,false,false);
					loadCityTable(rst,tableId);
					
		}	
	});
}

function loadCityTable(json,id){
	$("table[id='"+id+"'] tbody").empty();;

	if(json.result.data.length<=4){
		$("table[id='"+id+"'] thead").html("<th>城市</th><th>操作</th>");

		for ( var i = 0; i < json.result.data.length; i++) {
				$("table[id='"+id+"'] tbody").append("<tr></tr>");
			var cId=getHeadIndexValue(i, json, "id");
			var cName=getHeadIndexValue(i, json, "name");
			var htm="<td>"+cName+"</td><td><input class='common_btn' type='button' value='选择' onclick = \"chooseCity("+cId+",'"+cName+"')\"></td>	";
			$("table[id='"+id+"'] tbody tr:last").append(htm);
			
		}
	}else{
		$("table[id='"+id+"'] thead").html("<th>城市</th><th>操作</th><th>城市</th><th>操作</th><th>城市</th><th>操作</th><th>城市</th><th>操作</th>");	
	for ( var i = 0; i < json.result.data.length; i++) {
		if((i%4)==0){
			$("table[id='"+id+"'] tbody").append("<tr></tr>");
		}
		var cId=getHeadIndexValue(i, json, "id");
		var cName=getHeadIndexValue(i, json, "name");
		var htm="<td>"+cName+"</td><td><input class='common_btn' type='button' value='选择' onclick = \"chooseCity("+cId+",'"+cName+"')\"></td>	";
		$("table[id='"+id+"'] tbody tr:last").append(htm);
		
	}
	
	var count= 8- $("table[id='"+id+"'] tbody tr:last").children("td").length;
	for ( var j = 0; j < count; j++) {
		$("table[id='"+id+"'] tbody tr:last").append("<td></td>");
		
	}
	}

}
